Namespace Workflow

    Partial Class ListItems
        Inherits System.Web.UI.Page

#Region " Web Form Designer Generated Code "
        <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

        End Sub
        Private designerPlaceholderDeclaration As System.Object
        Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Init
        End Sub
#End Region

#Region "Form Controls"
        Protected WithEvents btnAdd As System.Web.UI.WebControls.Button
#End Region

#Region "Querystring"
        Public ReadOnly Property CategoryId As Integer
            Get
                Return CWeb.RequestInt("cid", CSession.CategoryId)
            End Get
        End Property
        Public ReadOnly Property StatusId As Integer
            Get
                Return CWeb.RequestInt("sid", CSession.Status)
            End Get
        End Property
        Public ReadOnly Property UserId As Integer
            Get
                Return CWeb.RequestInt("uid", CSession.UserId)
            End Get
        End Property
        Public ReadOnly Property Search As String
            Get
                Return CWeb.RequestInt("search")
            End Get
        End Property
        Public ReadOnly Property SortBy As String
            Get
                Return CWeb.RequestStr("sort")
            End Get
        End Property
        Public ReadOnly Property Desc As Boolean
            Get
                Return CWeb.RequestBool("desc")
            End Get
        End Property

        Public Function Url() As String
            Return String.Concat("Listitems.aspx?cid=", Str(CDropdown.GetInt(ddCategory)), "&sid=", Str(CDropdown.GetInt(ddStatus)), "&uid=", Str(CDropdown.GetInt(ddAssignedTo)), "&search=", HttpUtility.UrlDecode(txtSearch.Text))
        End Function
        Private Function Str(i As Integer) As String
            If Integer.MinValue = i Then Return String.Empty
            Return i.ToString
        End Function
#End Region

#Region "Event Handlers"
        Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            If Page.IsPostBack Then Exit Sub

            For Each i As CCategory In CCategory.Cache
                CDropdown.Add(ddCategory, Framework.CUtilities.NameAndCount(i.CategoryName, CItem.Cache.Search(Search, Integer.MinValue, i.CategoryId, StatusId, Integer.MinValue, CConfig.StatusComplete)), i.CategoryId)
            Next
            ddCategory.Items.Insert(0, New ListItem("-- All Projects --", Integer.MinValue))
            ddCategory.SelectedValue = CategoryId

            For Each i As CUser In CUser.Cache
                CDropdown.Add(ddAssignedTo, Framework.CUtilities.NameAndCount(i.UserName, CItem.Cache.Search(Search, i.UserId, CategoryId, StatusId, Integer.MinValue, CConfig.StatusComplete)), i.UserId)
            Next
            ddAssignedTo.Items.Insert(0, New ListItem("-- All Users --", Integer.MinValue))
            ddAssignedTo.SelectedValue = UserId

            For Each i As CStatus In CStatus.Cache
                CDropdown.Add(ddStatus, Framework.CUtilities.NameAndCount(i.StatusName, CItem.Cache.Search(Search, UserId, CategoryId, i.StatusId, Integer.MinValue, CConfig.StatusComplete)), i.StatusId)
            Next
            ddStatus.Items.Insert(0, New ListItem("-- Any Status --", Integer.MinValue))
            ddStatus.Items.Insert(0, New ListItem("Not Complete", "0"))
            ddStatus.SelectedValue = StatusId


            Try
                lnkLogout.Text = "Logout " & CUser.Cache.GetById(User.Identity.Name).UserName
            Catch ex As Exception
                Response.Redirect("logout.aspx")
            End Try
        End Sub
        Private Sub Page_PreRender(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.PreRender
            Dim assignedTo As Integer = CDropdown.GetInt(ddAssignedTo)
            Dim categoryId As Integer = CDropdown.GetInt(ddCategory)
            Dim status As Integer = CDropdown.GetInt(ddStatus)

            Dim s As String = txtSearch.Text

            ctrlHigh.Display(s, assignedTo, categoryId, status, CConfig.PriorityHigh, Url, SortBy, Desc)
            ctrlMedium.Display(s, assignedTo, categoryId, status, CConfig.PriorityMedium, Url, SortBy, Desc)
            ctrlLow.Display(s, assignedTo, categoryId, status, CConfig.PriorityLow, Url, SortBy, Desc)

            ddCategory.Font.Bold = ddCategory.SelectedIndex > 0
            ddAssignedTo.Font.Bold = ddAssignedTo.SelectedIndex > 0
            ddStatus.Font.Bold = ddStatus.SelectedIndex > 0
        End Sub

        Private Sub ddAssignedTo_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddAssignedTo.SelectedIndexChanged
            CSession.UserId = ddAssignedTo.SelectedValue
            Response.Redirect(Url)
        End Sub
        Private Sub ddStatus_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddStatus.SelectedIndexChanged
            CSession.Status = ddStatus.SelectedValue
            Response.Redirect(Url)
        End Sub
        Private Sub ddCategory_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ddCategory.SelectedIndexChanged
            CSession.CategoryId = ddCategory.SelectedValue
            Response.Redirect(Url)
        End Sub

        Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
            Response.Redirect("EditItem.aspx", True)
        End Sub
#End Region

    End Class

End Namespace
